package com.JavaTest5;

import java.util.ArrayList;
import java.util.Scanner;

interface IShape{
    double getArea();    //获取图形面积
    double getCircum();  //获取图形周长
    void moveTo(int posx,int posy);      //移动图形到指定的位置
    void zoom(double i);    //对图形进行缩放，缩放比例i>0
}

class Point{
    double x, y;

    public Point(){}
    public Point(double a, double b){
        this.x = a;
        this.y = b;
    }
    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }
}

class Circle implements IShape{
    private double radius, posx, posy;
    final double PI = 3.14159;

    public Circle(){}
    public Circle(double r, double x, double y){
        this.radius = r;
        this.posx = x;
        this.posy = y;
    }

    @Override
    public double getArea() {
        return PI * radius * radius;
    }

    @Override
    public double getCircum() {
        return 2 * PI * radius;
    }

    @Override
    public void moveTo(int x, int y){
        this.posy = y;
        this.posx = x;
    }

    @Override
    public void zoom(double i){
        this.radius = this.radius / i;
    }

    public String to_String(){
        return "圆形圆心坐标为：(" + this.posx + ", " + this.posy + "), 半径为：" + this.radius + ".";
    }

    public double getRadius() {
        return radius;
    }

    public void setRadius(double radius) {
        this.radius = radius;
    }

    public double getPosx() {
        return posx;
    }

    public void setPosx(double posx) {
        this.posx = posx;
    }

    public double getPosy() {
        return posy;
    }

    public void setPosy(double posy) {
        this.posy = posy;
    }
}

class Triangle implements IShape{
    Point a, b, c, d;
    double i, j, k;

    public Triangle() {}
    public Triangle(Point x, Point y, Point z){
        this.a = x;
        this.b = y;
        this.c = z;
        d = new Point();
        SetCenter_Point();
        SetSide_length();
    }

    public void SetCenter_Point(){
        d.x = (a.x + b.x + c.x) / 3;
        d.y = (a.y + b.y + c.y) / 3;
    }

    public void SetSide_length(){
        i = Math.sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y));
        j = Math.sqrt((a.x - c.x) * (a.x - c.x) + (a.y - c.y) * (a.y - c.y));
        k = Math.sqrt((c.x - b.x) * (c.x - b.x) + (c.y - b.y) * (c.y - b.y));
    }

    public String to_String(){
        return "三角形顶点坐标分别为:(" + a.x + ", " + a.y + "), (" + b.x + ", " + b.y + "), (" +
                + c.x + ", " + c.y + ").";
    }
    @Override
    public double getArea() {
        double p = getCircum() / 2;
        return Math.sqrt(p * (p - i) * (p - j) * (p - k));
    }

    @Override
    public double getCircum() {
        return i + j + k;
    }

    @Override
    public void moveTo(int posx, int posy) {
        double x = Math.abs(this.d.x - posx);
        double y = Math.abs(this.d.y - posy);
        boolean flag1, flag2;
        Point i, j, k;
        //T：向右， 上移， F：向左， 下移
        if((d.x - posx) < 0) flag1 = true;
        else flag1 = false;

        if((d.y - posy) < 0) flag2 = true;
        else flag2 = false;
        i = new Point((flag1 ? a.x + x : a.x - x),(flag2 ? a.y + y : a.y - y));
        j = new Point((flag1 ? b.x + x : b.x - x),(flag2 ? b.y + y : b.y - y));
        k = new Point((flag1 ? c.x + x : c.x - x),(flag2 ? c.y + y : c.y - y));

        setA(i);
        setB(j);
        setC(k);
    }

    @Override
    public void zoom(double n) {
        a.x /= n;
        a.y /= n;
        b.x /= n;
        b.y /= n;
        SetCenter_Point();
        SetSide_length();
    }

    public Point getA() {
        return a;
    }

    public void setA(Point a) {
        this.a = a;
    }

    public Point getB() {
        return b;
    }

    public void setB(Point b) {
        this.b = b;
    }

    public Point getC() {
        return c;
    }

    public void setC(Point c) {
        this.c = c;
    }

    public Point getD() {
        return d;
    }

    public void setD(Point d) {
        this.d = d;
    }

    public double getI() {
        return i;
    }

    public void setI(double i) {
        this.i = i;
    }

    public double getJ() {
        return j;
    }

    public void setJ(double j) {
        this.j = j;
    }

    public double getK() {
        return k;
    }

    public void setK(double k) {
        this.k = k;
    }

}

class Rectangle implements IShape{
    double len, wid;
    Point lu;

    public Rectangle(){}
    public Rectangle(Point a, double x, double y){
        super();
        this.lu = a;
        this.len = x;
        this.wid = y;
    }

    @Override
    public double getArea() {
        return len * wid;
    }

    @Override
    public double getCircum() {
        return (len + wid) * 2;
    }

    @Override
    public void moveTo(int posx, int posy) {
        lu.setX(posx);
        lu.setY(posy);
    }

    @Override
    public void zoom(double i) {
        len /= i;
        wid /= i;
    }

    public String to_String(){
        return "矩形左上顶点坐标为：(" + this.lu.x + ", " + this.lu.y + "), 长为：" + this.len + ", 宽为：" +
                + this.wid + ".";
    }

    public Point getLu() {
        return lu;
    }

    public void setLu(Point lu) {
        this.lu = lu;
    }

    public double getLen() {
        return len;
    }

    public void setLen(double len) {
        this.len = len;
    }

    public double getWid() {
        return wid;
    }

    public void setWid(double wid) {
        this.wid = wid;
    }
}

public class ShapeTest {
    static Scanner in = new Scanner(System.in);

    public static void printArea(IShape ishape){
        if(ishape instanceof Circle){
            System.out.print("圆形面积为：");
        }
        else if(ishape instanceof  Triangle){
            System.out.print("三角形面积为：");
        }
        else{
            System.out.print("矩形面积为： ");
        }
        System.out.println(ishape.getArea());
    }
    public static void printCircum(IShape ishape){
        if(ishape instanceof Circle){
            System.out.print("圆形周长为：");
        }
        else if(ishape instanceof  Triangle){
            System.out.print("三角形周长为：");
        }
        else{
            System.out.print("矩形周长为： ");
        }
        System.out.println(ishape.getCircum());
    }
    public static void moveTo(IShape ishape){
        int x, y;
        if(ishape instanceof Circle){
            System.out.print("输入需要改变的位置：x, y（圆形）");
        }
        else if(ishape instanceof  Triangle){
            System.out.print("输入需要改变的位置：x, y（三角形）");
        }
        else{
            System.out.print("输入需要改变的位置：x, y（矩形）");
        }
        x = in.nextInt();
        y = in.nextInt();
        ishape.moveTo(x, y);
    }
    public static void zoom(IShape ishape){
        int x;
        System.out.print("输入需要缩放的倍数: ");
        x = in.nextInt();
        ishape.zoom(x);
    }
    public static void to_String(IShape ishape){
        if(ishape instanceof Circle){
            System.out.println(((Circle) ishape).to_String());
        }
        else if(ishape instanceof  Triangle){
            System.out.println(((Triangle) ishape).to_String());
        }
        else{
            System.out.println(((Rectangle) ishape).to_String());
        }
    }

    public static void main(String[] args) {

        ArrayList<IShape> shape = new ArrayList<IShape> ();
        for(int i = 1; i <= 6; i ++ ){
            if(i == 1 || i == 2){
                System.out.println("输入圆的半径以及原点坐标：r, x, y");
                double r, x, y;
                r = in.nextDouble();
                x = in.nextDouble();
                y = in.nextDouble();
                Circle c = new Circle(r, x, y);
                shape.add(c);
            }
            else if(i == 3 || i == 4){
                System.out.println("输入三角形的三个顶点坐标：x1, y1, x2, y2, x3, y3");
                double x1, x2, x3, y1, y2, y3;
                x1 = in.nextDouble();
                y1 = in.nextDouble();
                x2 = in.nextDouble();
                y2 = in.nextDouble();
                x3 = in.nextDouble();
                y3 = in.nextDouble();
                Point a, b, c;
                a = new Point(x1, y1);
                b = new Point(x2, y2);
                c = new Point(x3, y3);
                Triangle t = new Triangle(a, b, c);
                shape.add(t);
            }
            else{
                System.out.println("输入矩形的左上顶点坐标以及长和宽： x, y, len, wid");
                double x, y, len, wid;
                x = in.nextDouble();
                y = in.nextDouble();
                len = in.nextDouble();
                wid = in.nextDouble();
                Point a = new Point(x, y);
                Rectangle r = new Rectangle(a, len, wid);
                shape.add(r);
            }
        }

        for(int i = 0; i < shape.size(); i ++ ){
            moveTo(shape.get(i));
            System.out.println("------------编号为" + i + "的图形移动后------------");
            to_String(shape.get(i));
        }

        for(int i = 0; i < shape.size(); i ++ ){
            System.out.print("编号为" + i + "的");
            printArea(shape.get(i));
            System.out.print("编号为" + i + "的");
            printCircum(shape.get(i));
        }

        for(int i = 0; i < shape.size(); i ++ ){
            zoom(shape.get(i));
            System.out.println("------------编号为" + i + "的图形缩放后------------");
            to_String(shape.get(i));
            System.out.print("编号为" + i + "的");
            printArea(shape.get(i));
            System.out.print("编号为" + i + "的");
            printCircum(shape.get(i));
        }
    }
}



